﻿using System.Security.Principal;
using UnionManager.Models;

namespace UnionManager.Infrastructure.Config
{
    public class EnhancedPrincipal : IPrincipal
    {
        private readonly IIdentity identity;
        private readonly TAIKHOAN userData;
        public static readonly EnhancedPrincipal Anonymous = new AnonymousPrincipal();

        public EnhancedPrincipal(IIdentity identity, TAIKHOAN userData)
        {
            this.identity = identity;
            this.userData = userData;
        }

        public bool IsInRole(string role)
        {
            return true;
        }

        public IIdentity Identity
        {
            get { return identity; }
        }

        public TAIKHOAN Data
        {
            get { return userData; }
        }

        private class AnonymousIdentity : IIdentity
        {
            public string Name
            {
                get { return "Anonymous"; }
            }

            public string AuthenticationType
            {
                get { return null; }
            }

            public bool IsAuthenticated
            {
                get { return false; }
            }
        }

        private class AnonymousPrincipal : EnhancedPrincipal
        {
            public AnonymousPrincipal()
                : base(new AnonymousIdentity(), new TAIKHOAN())
            {
            }
        }
    }
}